package hash_table;

import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * @author 老顾
 * @title: HashTableTest
 * @projectName java-restudy
 * @email: 1437594522@qq.com
 * @date 2022/11/7 14:36
 */
public class HashTableTest {

    private final static Logger logger = LoggerFactory.getLogger(HashTableTest.class);

    @Test
    public void testHashMap01(){
        Map<String, String> map = new HashMap01<>();
        map.put("01","豆豆");
        map.put("02","花花");
        logger.info("碰撞前 key：{} value：{}", "01", map.get("01"));

        // 下标碰撞
        map.put("09", "蛋蛋");
        map.put("12", "苗苗");
        logger.info("碰撞前 key：{} value：{}", "01", map.get("01"));
    }
    @Test
    public void testHashMap02(){
        Map<String, String> map = new HashMap02BySeparateChaining<>();
        map.put("01","豆豆");
        map.put("05","花花");
        logger.info("碰撞前 key：{} value：{}", "01", map.get("01"));

        // 下标碰撞
        map.put("09", "蛋蛋");
        map.put("12", "苗苗");
        logger.info("碰撞前 key：{} value：{}", "01", map.get("01"));
    }
    @Test
    public void testHashMap03(){
        Map<String, String> map = new HashMap03ByOpenAddressing<>();
        map.put("01","豆豆");
        map.put("05","花花");
        logger.info("碰撞前 key：{} value：{}", "01", map.get("01"));

        // 下标碰撞
        map.put("09", "蛋蛋");
        map.put("12", "苗苗");
        logger.info("碰撞前 key：{} value：{}", "01", map.get("01"));
        logger.info("数据结构：{}", map);
    }
    @Test
    public void testHashMap04(){
        Map<String, String> map = new HashMap04ByCoalescedHashing<>();
        map.put("01","豆豆");
        map.put("05","花花");
        logger.info("碰撞前 key：{} value：{}", "01", map.get("01"));

        // 下标碰撞
        map.put("09", "蛋蛋");
        map.put("12", "苗苗");
        logger.info("碰撞前 key：{} value：{}", "01", map.get("12"));
        logger.info("数据结构：{}", map);
    }
    @Test
    public void test_hashMap05() {
        java.util.Map<String, String> map = new HashMap05ByCuckooHashing<>();
        map.put("01", "花花");
        map.put("05", "豆豆");
        logger.info("碰撞前 key：{} value：{}", "01", map.get("01"));

        // 下标碰撞
        map.put("09", "蛋蛋");
        map.put("12", "苗苗");
        logger.info("碰撞前 key：{} value：{}", "01", map.get("12"));
        logger.info("数据结构：{}", map);
    }
}
